package com.zhangc.blog.base.validator;

/**
 * 功能描述:<br>
 *
 * @author wx:fdzhangc
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class ServiceException extends RuntimeException {
    public static final Object[] DEFAULT_ARGS = new Object[0];
    public static final ServiceException UNKNOWN;
    public static final ServiceException INVALID_PARAMETER;
    private static final long serialVersionUID = 4675005347418021820L;
    private final String name;
    private final String code;
    private final transient Object[] args;

    public ServiceException(String name) {
        this(name, DEFAULT_ARGS);
    }

    public ServiceException(String name, Object[] args) {
        super(name);
        this.name = name;
        this.args = args;
        this.code = "";
    }

    public ServiceException(String code, String message) {
        this("", code, message);
    }

    public ServiceException(String code, String message, Object[] args) {
        super(message);
        this.name = null;
        this.code = code;
        this.args = args;
    }

    private ServiceException(String name, String code, String message) {
        super(message);
        this.name = name;
        this.code = code;
        this.args = DEFAULT_ARGS;
    }

    public Object[] getArgs() {
        return this.args;
    }

    public String getName() {
        return this.name;
    }

    public String getCode() {
        return this.code;
    }

    public boolean hasCode() {
        return this.code != null;
    }

    public boolean hasMessage() {
        return this.getMessage() == null;
    }

    static {
        UNKNOWN = new ServiceException("系统忙，请稍后再试", DEFAULT_ARGS);
        INVALID_PARAMETER = new ServiceException("common.invalidParameter", "必填参数非法");
    }
}
